package system;

import java.sql.ResultSet;
import java.sql.SQLException;

import db.BaseDBProxy;

public class OrderProxy extends BaseDBProxy<Order> {
	private static final String[] sColumnNames = {
		"id", "user_id", "date", "book_id_and_count",
		"address", "state", "discount_coupons_count",
		"equal_coupons_count", "all_price"
	};
	
	private String mTableName = "orders";
	
	public OrderProxy() {
		this("orders");
	}
	
	public OrderProxy(String pTableName) {
		mTableName = pTableName;
	}
	
	@Override
	protected String[] getTableColumnNames() {
		return sColumnNames;
	}

	@Override
	protected Order inflate(ResultSet pResultSet) throws SQLException {
		Order order = new Order();
		order.id = pResultSet.getLong(sColumnNames[0]);
		order.user_id = pResultSet.getLong(sColumnNames[1]);
		order.date = pResultSet.getDate(sColumnNames[2]);
		order.book_id_and_count = pResultSet.getString(sColumnNames[3]);
		order.address = pResultSet.getString(sColumnNames[4]);
		order.state = OrderState.valueOf(pResultSet.getString(sColumnNames[5]));
		order.discount_coupons_count = pResultSet.getInt(sColumnNames[6]);
		order.equal_coupons_count = pResultSet.getInt(sColumnNames[7]);
		order.all_price = pResultSet.getDouble(sColumnNames[8]);
		
		return order;
	}

	@Override
	protected String getTableName() {
		return mTableName;
	}

	@Override
	protected String[] getRightValues(Order pItem) {
		// TODO Auto-generated method stub
		return null;
	}

}
